/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.Pessoa;
import model.PessoaDAO;


/**
 *
 * @author Eduarda
 */
public class TrataPessoa  extends Comando{

    public void executar(HttpServletRequest request, HttpServletResponse response ) throws ClassNotFoundException, SQLException, IOException, ServletException {
        response.setContentType("text/html;charset=UTF-8");

        String nome = request.getParameter("nome");
        String cpf = request.getParameter("cpf");
        String rg = request.getParameter("rg");
        String dataNasc = request.getParameter("dataNasc");
        String endereco = request.getParameter("endereco");
        String telefone = request.getParameter("telefone");
        String celular = request.getParameter("celular");
        String email = request.getParameter("email");
    
      Pessoa user = new Pessoa(nome, cpf, rg, null, endereco, telefone, celular, email);

        PrintWriter out = response.getWriter();
        try {

            PessoaDAO dao = new PessoaDAO();
            dao.inserir(user);
            response.sendRedirect("index_medico.jsp");
        } catch(SQLException ex){
            throw new ServletException(ex);
        }catch (ClassNotFoundException cnfe) {
            throw new ServletException(cnfe);
        }
            out.close();
    }
    
}





